package com.yuntian.mapper;


import com.yuntian.dto.ProductShippingDTO;
import com.yuntian.entity.OrderDetailData;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface OrderDetailDataMapper {

    @Insert("insert into T002(T00201,T00202,T00203,T00204)" + " values (#{T00201},#{T00202},#{T00203},#{T00204})")
    int insertDetail(OrderDetailData T002);


    /**
     * 商品別出庫表
     * 条件：交货希望日 = 指定日期
     */
    @Select("SELECT " +
            "  d.t00202         AS prodId, "+
            "  m.m00202         AS prodName, " +
            "  d.t00201         AS orderCode, " +
            "  d.t00203         AS qty, " +
            "  SUM(d.t00203) OVER (PARTITION BY d.t00202) AS totalQty " +
            "FROM T002 d " +
            "JOIN T001 h ON d.t00201 = h.t00101 " +
            "JOIN M002 m ON d.t00202 = m.m00201 " +
        "WHERE h.t00103 = #{deliveryDate} " +
                "ORDER BY d.t00202, d.t00201")

    List<ProductShippingDTO> selectProductShippingList(@Param("deliveryDate") LocalDate deliveryDate);

}
